package com.example.gw_back_end.controller;

import com.example.gw_back_end.domain.Result;
import com.example.gw_back_end.service.mongodb.SettingService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("setting")
public class SettingController {

    private final SettingService settingService;
    public SettingController(SettingService settingService) {
        this.settingService = settingService;
    }

    // 获取用户设置
    @GetMapping("get_setting")
    public Result getSetting() {
        Object setting = settingService.getSetting();
        if (setting != null){
            return Result.success(setting);
        } else {
            return Result.error();
        }
    }

    // 更新用户设置
    @PutMapping("update_setting")
    public Result update(Object setting){
        Object newSetting = settingService.updateSetting(setting);
        if (newSetting != null) {
            return Result.success(newSetting);
        } else {
            return Result.error();
        }
    }
}
